package com.smartview.jboss.spring.model;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

@Service
public class YahooData {
	public InputStream retrieveWeather(String zip) throws IOException {
//		System.out.println("We are retrieving data from Yahoo...");
		Logger logger = Logger.getLogger(this.getClass());
		logger.debug("We are retrieving data from Yahoo...");
		
        // Create a connection with Yahoo Weather
    	URL url = new URL("http://weather.yahooapis.com/forecastrss?p=" + zip);
    	URLConnection conn = url.openConnection();
    	InputStream in = conn.getInputStream();

    	return in;
	}
	
	public InputStream retrieveNews() throws IOException {
//		System.out.println("We are retrieving data from Yahoo...");
/*		Logger logger = Logger.getLogger(this.getClass());
		logger.debug("We are retrieving data from Yahoo...");*/
		
        // Create a connection with Yahoo Weather
    	URL url = new URL("http://rss.news.yahoo.com/rss/");
    	URLConnection conn = url.openConnection();
    	InputStream in = conn.getInputStream();

    	return in;
	}
	
	public InputStream retrieveCompany(String key) throws IOException {
//		System.out.println("We are retrieving data from Yahoo...");
/*		Logger logger = Logger.getLogger(this.getClass());
		logger.debug("We are retrieving data from Yahoo...");*/
		
        // Create a connection with Yahoo Weather
    	URL url = new URL("http://finance.yahoo.com/rss/headline?s=" + key);
    	URLConnection conn = url.openConnection();
    	InputStream in = conn.getInputStream();

    	return in;
	}
}
